package com.jr.service.impl;


import com.jr.dao.EnterpriseDao;
import com.jr.dao.SupplierBlackListDao;
import com.jr.dao.UserDao;
import com.jr.dao.impl.EnterpriseDaoImpl;
import com.jr.dao.impl.SupplierBlackListDaoImpl;
import com.jr.dao.impl.UserDaoImpl;
import com.jr.entry.Enterprise;
import com.jr.entry.SupplierBlackList;
import com.jr.entry.User;
import com.jr.pojo.InformationInBlackMess;
import com.jr.service.SupplierBlackListService;
import com.jr.util.BlackPageHelper;

import java.util.ArrayList;

public class SupplierBlackListServiceImpl implements SupplierBlackListService {
    SupplierBlackListDao  supplierBlackListDao=new SupplierBlackListDaoImpl();
    UserDao userDao=new UserDaoImpl();
    EnterpriseDao enterpriseDao=new EnterpriseDaoImpl();
    @Override
    public boolean insertSupplierBlackList(String account, String enterpriseName, String reason) {
        //根据账户查企业id
        User user=userDao.selectUserByAccount(account);
        String enterpriseId=user.getEnterpriseId();
        //通过企业名查供应商id
        Enterprise enterprise=enterpriseDao.selectEnterpriseByName(enterpriseName);
        Integer supplierId= enterprise.getId();
        //封装信息
        SupplierBlackList supplierBlackList=new SupplierBlackList();
        supplierBlackList.setEnterpriseId(Integer.parseInt(enterpriseId));
        supplierBlackList.setSupplierId(supplierId);
        supplierBlackList.setReason(reason);
        return supplierBlackListDao.insertSupplierBlackList(supplierBlackList);
    }

    @Override
    public boolean deleteSupplierBlackList(String account, String enterpriseName) {
        //根据账户查企业id
        User user=userDao.selectUserByAccount(account);
        String enterpriseId=user.getEnterpriseId();
        //通过企业名查供应商id
        Enterprise enterprise=enterpriseDao.selectEnterpriseByName(enterpriseName);
        Integer supplierId= enterprise.getId();

        return supplierBlackListDao.deleteSupplierBlackListByEnterpriseIdAndSupplierId(enterpriseId,supplierId.toString());
    }

    @Override
    public ArrayList<InformationInBlackMess> selectAllMess(String account, String name, BlackPageHelper blackPageHelper) {
        return supplierBlackListDao.selectAllSupplierBlackList(account,name,blackPageHelper);
    }
    public  ArrayList<String> selectNoneBlacklistNameByEname(String ename){
        return null;
    }

    @Override
    public int selectSize(String account, String name) {
        return supplierBlackListDao.selectSize(account,name);
    }
}
